﻿Imports Microsoft.VisualBasic
Imports System.Security.Cryptography

''' <summary>
''' Lẩu các loại hàm khác nhau
''' </summary>
''' <remarks></remarks>
Public Class pAnother
    Public Shared Function MD5(ByVal str As String) As String
        If str.Length <= 0 Then
            str = "1"
        End If
        Dim provider As MD5CryptoServiceProvider = New MD5CryptoServiceProvider()
        Dim bytValue() As Byte
        Dim bytHash() As Byte
        Dim strOutput As String = ""
        Dim i As Integer
        bytValue = System.Text.Encoding.Unicode.GetBytes(str)
        bytHash = provider.ComputeHash(bytValue)
        provider.Clear()
        For i = 0 To bytHash.Length - 1
            strOutput &= bytHash(i).ToString("x").PadLeft(2, "0")
        Next
        Return strOutput
    End Function
    ''' <summary>
    ''' Ghi tên, nội dung, số ngày tồn tại của Cookie
    ''' </summary>
    ''' <param name="tenCookie">Tên (nam,nam1,macuoc)</param>
    ''' <param name="Noidung">Nội dung (năm hoặc mã cuộc)</param>
    ''' <param name="songay">Số ngày tồn tại</param>
    ''' <remarks></remarks>
    Public Shared Sub GhiCookie(ByVal tenCookie As String, ByVal Noidung As String, ByVal songay As Int32)
        Dim appCookie As New HttpCookie(tenCookie)
        appCookie.Value = Noidung
        'appCookie.Domain = AppDomain.CurrentDomain.FriendlyName
        appCookie.Expires = DateTime.Now.AddDays(songay)
        'appCookie.Path = "/Application1"
        System.Web.HttpContext.Current.Response.Cookies.Add(appCookie)
    End Sub

    ''' <summary>
    ''' Đọc cookie (nam, nam1, macuoc)
    ''' </summary>
    ''' <param name="tenCookie">Tên, giả sử (nam, nam1, macuoc)</param>
    ''' <returns>Nội dung cookie</returns>
    ''' <remarks></remarks>
    Public Shared Function DocCookie(ByVal tenCookie As String) As String
        If Not System.Web.HttpContext.Current.Request.Cookies(tenCookie) Is Nothing Then
            Dim aCookie As HttpCookie = System.Web.HttpContext.Current.Request.Cookies(tenCookie)
            Return System.Web.HttpContext.Current.Server.HtmlEncode(aCookie.Value)
        Else
            Return ""
        End If
    End Function
End Class
'Các cookie dự kiến ghi và đọc
'